package com.koron.css2.serviceManage.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.BankInterfaceConfigBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.mapper.BankInterfaceConfigMapper;
import com.koron.css2.serviceManage.utils.CommonUtils;
import com.koron.util.Constant;
import com.koron.util.DBSourceUtils;
import com.koron.util.JsonUtils;
import com.mysql.cj.util.StringUtils;
import net.sf.json.JSONObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;
/**
 * 编辑银行直连配置
 * @author 李攀
 *
 */
public class BankInterfaceConfigUpdate implements ServerInterface{
	
private static Logger logger = LogManager.getLogger(BankInterfaceConfigUpdate.class);
	
	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {			
		JSONObject pa=JSONObject.fromObject(req.getData());
		String companyNo=pa.getString("companyNo");	
		BankInterfaceConfigMapper mapper = factory.getMapper(BankInterfaceConfigMapper.class,DBSourceUtils.getDbEnv(companyNo));
		BankInterfaceConfigBean bean = null;
		pa.remove("companyNo");//移除参数
		try {
			bean = JsonUtils.objectToPojo(pa, BankInterfaceConfigBean.class);			
			bean.setUpdateName(userInfo.getUserInfo().getName());
			bean.setUpdateTime(CommonUtils.getCurrentTime());
			if (StringUtils.isNullOrEmpty(bean.getBankInterfaceId())) {
				return MessageBean.create(Constant.ILLEGAL_PARAMETER, "id为空", void.class);
			}
			mapper.updateBankInterfaceConfig(bean);
		} catch (Exception e) {
			logger.error("非法参数",e);
			return MessageBean.create(Constant.ILLEGAL_PARAMETER, "非法参数", void.class);
		}
		return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", void.class);
	}


}
